package hot100.logos11To20;

/**
 * @author logos
 * date 2025/7/10 11:53
 * @version v1.0
 * @Package hot100
 */
public class logos13 {

    /**
     * 13. 最大子数组和
     * https://leetcode.cn/problems/maximum-subarray/description/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int maxSubArray(int[] nums) {
            int n = nums.length;
            int ans = nums[0];
            int pre = nums[0];
            for (int i = 1; i < n; i++) {
                pre = Math.max(pre + nums[i], nums[i]);
                ans = Math.max(ans, pre);
            }
            return ans;
        }
    }
}
